

import org.apache.spark.{SparkConf, SparkContext}

object WordCountDemo {
  def main(args: Array[String]): Unit = {
    //词频统计
    //创建Spark Context对象
    //创建配置对象
    val conf: SparkConf = new SparkConf().setAppName("wordscount").setMaster("local[2]")
    val sc = new SparkContext(conf)
    //设置日志的级别
    sc.setLogLevel("WARN")
    val result: Array[(String, Int)] = sc.textFile("data/words.txt").flatMap(_.split(" ")).map((_, 1)).reduceByKey(_ + _).collect
    println(result.toBuffer)



  }
}
